package com.example.wechat.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.example.wechat.R;
import com.example.wechat.adapter.FavoritesArticleAdapter;
import com.example.wechat.model.FavoriteArticle;
import java.util.ArrayList;
import java.util.List;

public class FavoritesArticleFragment extends Fragment {
    private RecyclerView recyclerView;
    private FavoritesArticleAdapter adapter;
    private List<FavoriteArticle> favoriteArticles;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_favorites_article, container, false);
        
        recyclerView = view.findViewById(R.id.recycler_view);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        
        favoriteArticles = new ArrayList<>();
        adapter = new FavoritesArticleAdapter(favoriteArticles);
        recyclerView.setAdapter(adapter);
        
        loadFavoriteArticles();
        
        return view;
    }

    private void loadFavoriteArticles() {
        // TODO: 从数据库或服务器加载收藏的文章
        // 这里添加一些测试数据
        favoriteArticles.add(new FavoriteArticle(
            "微信小程序开发指南",
            "本文介绍了微信小程序的基本开发流程和注意事项...",
            "https://example.com/article1",
            System.currentTimeMillis()
        ));
        favoriteArticles.add(new FavoriteArticle(
            "Android开发最佳实践",
            "本文总结了Android开发中的一些最佳实践和常见问题解决方案...",
            "https://example.com/article2",
            System.currentTimeMillis() - 86400000
        ));
        adapter.notifyDataSetChanged();
    }
} 